#pragma once
#include <QQuickItem>
#include "PropertyHelper.h"
#include <QImage>
class YUVItem : public QQuickItem
{
    Q_OBJECT

    AUTO_PROPERTY(QUrl, source, {})
    AUTO_PROPERTY(int64_t, bitrate, 0)

    using Super = QQuickItem;

    QML_NAMED_ELEMENT(RectangleItem)
public:
    YUVItem(QQuickItem *parent = nullptr);
    virtual ~YUVItem();


protected:
    virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
protected slots:
    void onTimeout();
    void onSourceChanged();
private:
    bool mGeometryChanged = true;
    bool mSourceChanged = true;
    bool mBitrateChanged = true;
    QTimer *mTimer = nullptr;
    QByteArray mData;
    int mDataW = 0;
    int mDataH = 0;
    int mDataOffset= 0;
    QByteArray mDataY;
    QByteArray mDataU;
    QByteArray mDataV;
    QImage mImageY;
    QImage mImageU;
    QImage mImageV;
    bool mYUVChanged = false;
};
